package com.chixing.controller;

import com.chixing.service.CarService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: wtl
 * @Date: 2021/10/14/10:41
 * @Description:
 */
@Controller
public class CarController {
    @Autowired
    private CarService carService;

    @GetMapping("car/conditions")
    @ResponseBody
    public ServerResponse FindByConditions (String carCategoryName,
                                           String carBrandname,
                                          Integer pageNum) {
        if (pageNum == null)
            pageNum = 1;
        return carService.FindByConditions(carCategoryName, carBrandname, pageNum);
    }

    @GetMapping("car/detail/{carId}")
    public ModelAndView getCarDetail(@PathVariable("carId") Integer carId){
        ServerResponse serverResponse = carService.getCarDetail(carId);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("serverResponse",serverResponse);
        modelAndView.setViewName("review/review");
        return modelAndView;
    }
}
